package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import controller.ControllerPrincipal;

import xmlObjects.ClienteBean;

import beans.CondicionOperacionBean;
import beans.EntidadBean;
import beans.FinanciacionBean;
import beans.PagoContadoBean;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class AltaCliente extends JFrame {
	private JLabel LNombre;
	private JLabel JCuil;
	private JLabel LIva;
	private JButton BAlta;
	private JButton BAgregarCond;
	private JTextField TextDias;
	private JTextField TextPorcentaje;
	private JLabel LCantDias;
	private JLabel LPorcentaje;
	private JLabel LCond;
	private JTextField TextIva;
	private JTextField TextCuil;
	private JTextField TextRS;
	private JLabel JAltaCliente;

	private List<CondicionOperacionBean> condiciones = null;

	public AltaCliente() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				{
					LNombre = new JLabel();
					getContentPane().add(LNombre);
					LNombre.setText("Razon Social: ");
					LNombre.setBounds(23, 63, 82, 15);
				}
				{
					JAltaCliente = new JLabel();
					getContentPane().add(JAltaCliente);
					JAltaCliente.setText("Alta de Clientes");
					JAltaCliente.setBounds(98, 22, 90, 15);
				}
				{
					JCuil = new JLabel();
					getContentPane().add(JCuil);
					JCuil.setText("Cuil: ");
					JCuil.setBounds(23, 90, 29, 15);
				}
				{
					TextRS = new JTextField();
					getContentPane().add(TextRS);
					TextRS.setBounds(123, 60, 94, 22);
				}
				{
					TextCuil = new JTextField();
					getContentPane().add(TextCuil);
					TextCuil.setBounds(123, 87, 94, 22);
				}
				{
					LIva = new JLabel();
					getContentPane().add(LIva);
					LIva.setText("Condicion Iva: ");
					LIva.setBounds(23, 117, 88, 15);
				}
				{
					TextIva = new JTextField();
					getContentPane().add(TextIva);
					TextIva.setBounds(123, 114, 94, 22);
				}
				{
					LCond = new JLabel();
					getContentPane().add(LCond);
					LCond.setText("Condiciones");
					LCond.setBounds(54, 164, 69, 15);
				}
				{
					LPorcentaje = new JLabel();
					getContentPane().add(LPorcentaje);
					LPorcentaje.setText("Porcentaje: ");
					LPorcentaje.setBounds(23, 191, 69, 15);
				}
				{
					LCantDias = new JLabel();
					getContentPane().add(LCantDias);
					LCantDias.setText("Cantidad de Dias: ");
					LCantDias.setBounds(23, 224, 113, 15);
				}
				{
					TextPorcentaje = new JTextField();
					getContentPane().add(TextPorcentaje);
					TextPorcentaje.setBounds(136, 188, 81, 22);
				}
				{
					TextDias = new JTextField();
					getContentPane().add(TextDias);
					TextDias.setBounds(136, 221, 81, 22);
				}
				{
					BAgregarCond = new JButton();
					getContentPane().add(BAgregarCond);
					BAgregarCond.setText("Agregar Condicion");
					BAgregarCond.setBounds(233, 200, 120, 31);
					BAgregarCond.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							if (TextDias.getText() == "") {
								condiciones.add(new PagoContadoBean(Float
										.parseFloat(TextPorcentaje.getText())));
							} else {
								condiciones.add(new FinanciacionBean(Integer
										.parseInt(TextDias.getText()), Float
										.parseFloat(TextPorcentaje.getText())));
							}

						}
					});
				}
				{
					BAlta = new JButton();
					getContentPane().add(BAlta);
					BAlta.setText("Alta");
					BAlta.setBounds(143, 271, 80, 59);
					BAlta.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent arg0) {
							try {
								if (ControllerPrincipal.getInstancia()
										.validarClienteExistenteByCuil(
												TextCuil.getText())) {
									EntidadBean c = new EntidadBean(TextCuil
											.getText(), TextRS.getText(),
											TextIva.getText(), condiciones);
									ControllerPrincipal.getInstancia()
											.AltaCliente(c);
								}
							} catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}

						}
					});
				}
			}
			{
				this.setSize(371, 363);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		pack();
	}

}
